﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TireService.Data;

namespace TireService.Website.Kunde
{
    public partial class Index : System.Web.UI.Page
    {
        #region Public Properties

        public int CustomerId
        {
            get
            {
                if (ViewState["_customerid"] != null)
                    return (int)ViewState["_customerid"];
                else
                    return (int)Session["CustomerId"];
            }
            set
            {
                ViewState["_customerid"] = value;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnBooking_Click(object sender, ImageClickEventArgs e)
        {
            GetBookingLink();
        }

        protected void lbtnBooking_Click(object sender, EventArgs e)
        {
            GetBookingLink();
        }

        private void GetBookingLink() 
        {
            TireServiceDB db = new TireServiceDB();

            // Fetch Customer
            Customer customer = db.GetCustomer(this.CustomerId);

            if (customer == null)
            {
                // Error
                throw new ArgumentException("Kunde blev ikke fundet");
            }

            // Set values in edit form
            if (customer.UserId != null)
            {
                // HACK: Weblink should be a dynamic parameter
                Response.Redirect(string.Format("http://www.mobilhjulskift.dk/Booking/Booking.aspx?uid={0}", customer.UserId.ToString()));
            }
            else
            {
                // Error
                throw new ArgumentException("Kunde har ikke et brugerlogin - venligst opret dette først.");
            }
        }
    }
}